#include "FpMath.h"

#include <cmath>

FP_AlMath_Begin

double FpMath::FpRounding(double ori, int bitNum)
{
	int multiple = 1;
	for (int ii = 0;ii<bitNum;ii++)
	{
		multiple *= 10;
	}
	ori *= multiple;
	ori = round(ori);
	ori /= multiple;
	return ori;
}

int FpMath::FpMaxCommonDivisor(int aa, int bb)
{
	if (aa <=0 || bb <=0)
	{
		return 0;
	}
	while (bb != 0) {
		int temp = bb;
		bb = aa % bb;
		aa = temp;
	}
	return aa;
}


int FpMath::FpMinCommonMultiple(int aa, int bb)
{
	return (aa * bb) / FpMaxCommonDivisor(aa, bb);
}

int FpMath::RoundingIndividualBit(int aa)
{
	int bb = aa % 10;
	if (bb < 5) {
		aa -= bb;
	}
	else {
		aa += 10 - bb;
	}
	return aa;
}



Fp_AlMath_End